package reflect;

import domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class ReflectDemo3 {

    public static void main(String[] args) throws Exception {


        // 1. 获取Person的Class对象
        Class personClass = Person.class;

        // 获取构造方法们  getConstructor(类<?>... parameterTypes)

        Constructor constructor = personClass.getConstructor(String.class, int.class);
        System.out.println(constructor);
        Object person = constructor.newInstance("张三", 15);
        System.out.println(person);

        System.out.println("--------------------");

        Constructor constructor1 = personClass.getConstructor();
        Object person1 = constructor1.newInstance();
        System.out.println(person1);

        Object o = personClass.newInstance();
        System.out.println(o+"<--这是Class对象提供的调用空参构造的创建对象的方法：");


    }

}
